package com.dzk.cp.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	
	public static String dateToStr(Date date, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
	
	public static String dateToStr(Date date) {
		return dateToStr(date, "yyyy-MM-dd");
	}

	public static Date strToDate(String str, String pattern) {
		Date date = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(pattern);
			date = sdf.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	public static Date strToDate(String str) {
		return strToDate(str, "yyyy-MM-dd");
	}
	
	public static Date addDate(Date date, int n) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, n);
		return calendar.getTime();
	}

	public static String addDateStr(String str, int n) {
		Date date = addDate(strToDate(str), n);
		return dateToStr(date);
	}

}
